package io.renren.modules.live.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.live.entity.FanweAnchorEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import oracle.jdbc.proxy.annotation.Post;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.live.entity.FanweAnchoridUseridEntity;
import io.renren.modules.live.service.FanweAnchoridUseridService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-11-19 12:07:23
 */
@Log4j2
@Api(tags = "关注模块接口")
@RestController
@RequestMapping("attention")
public class FanweAnchoridUseridController {
    @Autowired
    private FanweAnchoridUseridService fanweAnchoridUseridService;


    /**
     * 列表
     */
    @ApiOperation("根据用户ID 查询关注的所有主播信息")
    @GetMapping("/attentionAnchorInfo")
    //@RequiresPermissions("live:fanweanchoriduserid:list")
    public R list(@ApiParam(value = "用户ID",required = true) Integer userId){
        List<FanweAnchorEntity> anchorList= fanweAnchoridUseridService.attentionAnchorInfo(userId);
        if(anchorList.isEmpty()&&anchorList.size()==0){
            return R.error("您没有关注任何主播");
        }
        return R.ok("查询成功").put("anchorList", anchorList);
    }



    /**
     * 保存
     */
    @ApiOperation("根据用户ID添加关注的主播信息")
    @PostMapping("/addAttentionAnchorInfo")
    //@RequiresPermissions("live:fanweanchoriduserid:save")
    public R addAttentionAnchorInfo(@ApiParam(value = "用户ID",required = true) Integer userId,
                                    @ApiParam(value = "主播ID",required = true) Integer anchorId){
            R r = fanweAnchoridUseridService.addAttentionAnchorInfo(userId, anchorId);
        return R.ok(r);
    }

    /**
     * 删除
     */
    @ApiOperation("根据用户ID删除关注的主播信息")
    @DeleteMapping("/deleteaAttentionAnchorInfo")
    //@RequiresPermissions("live:fanweanchoriduserid:delete")
    public R delete(@ApiParam(value = "用户ID",required = true) Integer userId,
                    @ApiParam(value = "主播ID",required = true) Integer anchorId){
        try {
            fanweAnchoridUseridService.deleteaAttentionAnchorInfo(userId,anchorId);
        }catch (Exception e){
            log.info(e+"根据用户ID删除关注的主播信息失败");
        }
        return R.ok("删除关注主播成功");
    }
}
